import { ApiCall } from "tsrpc";
import { ReqSign, ResSign } from "../../../shared/master/body/PtlSign";
import { player } from "../../../model/fight/body/player";
import { rank_type, taskKey } from "../../../shared/interface";
import app, { xlsxCfgNames } from "../../../app";
import { Tpl_gifts_default, template } from "../../../shared/master/MsgAction";
import god from "../../../god";
import manage_task from "../../model/manage/manage_task";

export default async function (call: ApiCall<ReqSign, ResSign>) {
    call.succ({})
    let user = call.req._player as player;
    let jude = app.isSameDay(Date.now(), user.log.sign_last_time)
    if (jude) {
        user.sendMsg(template.default, '明天再来签到吧')
        return;
    }
    user.log.sign_last_time = Date.now();
    let signCont = user.log.add(rank_type.签到次数, 1)
    manage_task.event(taskKey.签到一次,1,user);

    
    let items = god.getRandomItems(1000, `${user.name}·签到获得`, xlsxCfgNames.签到奖励表)
    let list = user.addItems(items)
    list.push({name:`🥳今天是你来到进化岛的第${signCont}天`,num:1})
    let tpl: Tpl_gifts_default = {
        title: `签到成功`,
        items: list
    }
    user.sendMsg(template.通用奖励, tpl)
}